﻿using MongoDB.Driver;
using Sustainalytics.BusinessResearchProductStates.Entities.ResearchState;
using Sustainalytics.ClientDW.Entities;
using System;
using System.Threading.Tasks;

namespace Sustainalytics.ScreeningTool.Synchronization.Caches
{
    public class ExcludedCompaniesCache : HashSetCache<Guid>
    {
    }

    public class ExcludedCompaniesCacheLoader : ICacheLoader<ExcludedCompaniesCache>
    {
        private readonly ExcludedCompaniesCache _cache;
        private readonly IMongoCollection<CorporateData> _collection;

        public ExcludedCompaniesCacheLoader(ExcludedCompaniesCache cache, IMongoCollection<CorporateData> collection)
        {
            _cache = cache;
            _collection = collection;
        }

        public async Task LoadAsync(ClientFacingProduct clientFacingProduct)
        {
            var excludedCompanies = await _collection.GetClientSpecificCompanyIdsAsync(clientFacingProduct);
            _cache.AddItems(excludedCompanies);
        }
    }
}
